/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit;

import picounit.features.registry.RegistryEntries;
import junit.framework.TestResult;

public class TestRunner {
	private final RegistryEntries registryEntries = new RegistryEntries();
	
	public TestResult runSingle(Class<?> testClass) {
		return runSingle(testClass, Test.class);
	}

	public TestResult runSingle(Class<?> testClass, Class<?> markerClass) {
		TestResult testResult = new TestResult();

		picoUnit(markerClass).generateSingleJUnitTest(testClass).run(testResult);

		return testResult;
	}
	
	public TestResult run(Class<?> testClass) {
		return run(testClass, Test.class);
	}

	public TestResult run(Class<?> testClass, Class<?> markerClass) {
		TestResult testResult = new TestResult();

		picoUnit(markerClass).generateJUnitTest(testClass).run(testResult);

		return testResult;
	}

	public void register(Class<?> implementationClass) {
		registryEntries.register(implementationClass);
	}
	
	private PicoUnit picoUnit(Class<?> markerClass) {
		PicoUnit picoUnit = new PicoUnit("Test Runner", markerClass);

		registryEntries.registerWith(picoUnit);

		return picoUnit;
	}
}